// pages/position/position.js
import {area} from '../../utils/area.js'

const app = getApp()

Component({
    properties: {},
    data: {
        //
        imgs:{
            toastClose: '/assets/img/close_icon.png',
        },

        currentIdx: 0,
        toView: 'a1',
        // 省份
        provinceList: [],
        provinceIndex: 40,
        provinceName: '',
        province: 0,
        provinceNameId: null,
        // 市
        cityList: [],
        cityListIndex: 30,
        cityListName: '',
        city: 0,
        showProvince: true,
        cityListId: null,
        // 区
        areaList: [],
        areaListIndex: 40,
        areaListName: '',
        showArea: true,
        areaListId: null,
        // 参数
        list: {
            uid: null,
            token: null
        },
    },
    attached: function () {
        this.setData({
            provinceList: area
        })
    },
    methods: {
        /**
         * 点击右上角的关闭按钮，隐藏弹窗
         * @private
         */
        _closeToast(){
            this.triggerEvent('showTab');
        },
        // swiper
        _changeCurrent(e) {
            let index = e.detail.current
            this.setData({
                currentIdx: index
            })
        },
        // 点击省份
        _bindProvince(e) {
            let name = e.currentTarget.dataset.name
            let index = e.currentTarget.dataset.index
            this.data.provinceNameId = e.currentTarget.dataset.id
            let province = this.data.province + 1
            if (province > 1) {
                this.data.cityListName = ''
                this.data.cityListIndex = 30
                this.data.areaListName = ''
                this.data.areaListIndex = 40
                this.data.showArea = true
            }
            this.setData({
                provinceName: name,
                cityList: this.data.provinceList[index].cityList,
                provinceIndex: index,
                currentIdx: 1,
                province: this.data.province + 1,
                cityListName: this.data.cityListName,
                cityListIndex: this.data.cityListIndex,
                areaListName: this.data.areaListName,
                areaListIndex: this.data.areaListIndex,
                showArea: this.data.showArea,
                showProvince: false
            })
        },
        // 点击市
        _bindcity(e) {
            let name = e.currentTarget.dataset.name
            let index = e.currentTarget.dataset.index
            let city = this.data.city + 1
            this.data.cityListId = e.currentTarget.dataset.id
            if (city > 1) {
                this.data.areaListName = ''
                this.data.areaListIndex = 40
            }
            this.setData({
                cityListName: name,
                areaList: this.data.cityList[index].areaList,
                cityListIndex: index,
                currentIdx: 2,
                city: city,
                areaListName: this.data.areaListName,
                areaListIndex: this.data.areaListIndex,
                showArea: false
            })
        },
        // 点击县
        _bindArea(e) {
            let name = e.currentTarget.dataset.name
            let index = e.currentTarget.dataset.index
            this.setData({
                areaListName: name,
                areaListIndex: index,
            })
            this.triggerEvent('calendarchange', {
                provinceName: this.data.provinceName,
                cityListName: this.data.cityListName,
                areaListName: name,
                provinceNameId: this.data.provinceNameId,
                cityListId: this.data.cityListId,
                areaListId: e.currentTarget.dataset.id,
            });
            this.triggerEvent('showTab');
        },
        // 点击title
        _bindTileProvince(e) {
            let index = e.currentTarget.dataset.index
            this.setData({
                currentIdx: index
            })
        }
    }
})